﻿using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration;
using Microsoft.Practices.Unity;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace WDA.Core
{
   /// <summary>
   /// Configurator implementation based on PIAB configuration section.
   /// </summary>
   public sealed class PiabConfigModuleConfigurator : IModuleConfigurator
   {
      private readonly PolicyInjectionSettings _configElement;
      private readonly string _targetModule;

      /// <summary>
      /// Creates new configurator object.
      /// </summary>
      /// <param name="targetModule">Name of target module's container.</param>
      /// <param name="configElement">Configuration settings.</param>
      public PiabConfigModuleConfigurator(string targetModule, PolicyInjectionSettings configElement)
      {
         _targetModule = targetModule;
         _configElement = configElement;
      }

      #region IModuleConfigurator Members
      public bool ShouldApply(string moduleContainerName)
      {
         return _targetModule == moduleContainerName;
      }
      public void Apply(IUnityContainer moduleContainer)
      {
         _configElement.ConfigureContainer(moduleContainer, new SystemConfigurationSource());
      }
      #endregion
   }
}
